from Crypto.Cipher import AES
import base64
import time
from pkcs7 import PKCS7Encoder


def encrypt_vip(plaintext):
    key = 'DFFD1CF28E8DBB1F36F9DE50C06A942B'.encode('utf-8')
    iv = b'DFFD1CF28E8DBB1F'
    encoder = PKCS7Encoder()
    aes = AES.new(key, AES.MODE_CBC, iv)
    padtext = encoder.encode(plaintext)
    print('plaintext: %s' % plaintext)
    print('padtext: %s' % padtext)
    aesbytes = aes.encrypt(padtext.encode('utf8'))
    return base64.b64encode(aesbytes).decode('utf8')


if __name__ == '__main__':
    content = "VIP*%s*%s" % (
    '%.5f' % (time.time() + 3600 * 100), r'\wanfangzl2017_20180829001\W_ZL_6778201610987323463.pdf')

    info = encrypt_vip(content)
    print('info: %s' % info)
    url = r'http://192.168.30.209:8080/DownPaper.dll?PickExtRes&ResName=ZL&CDNum=WANFANGZL2017_20180829001&info=%s&title=W_ZL_6778201610987323463.pdf'
    url = url % info
    print('url: %s' % url)
